#pragma warning(disable:4786)


#ifndef PAGELIST_H
#define PAGELIST_H
	#include "PageList.h"
#endif


#include "PTable.h"

#include "VecUtility.h"
#include "ppc_impl.h"
#include "NumStr.h"
#include "StrNum.h"
#include <sstream>
#include "PDoc.h"
#include "CoreMass.h"
#include <time.h>

#include <direct.h>
#include <stdlib.h>
#include <stdio.h>

#include <algorithm>

#include <string>
using namespace std;
#include <crtdbg.h>

istream* input;

int main(int argc, char* argv[ ]) 

{
	string name, name_file_IN, name_file_OUT, name_file_LOG;
	int err = 0;
	if (argc == 1)
	{
		char input_utente[30];
		cout<<"Inserisci il nome del file di input: ";
		cin >> input_utente;
		name = input_utente;
		err = 0;
	}
	else if (argc == 2)
	{
/////////////////////////////////////////////////////////
		input = new istringstream(argv[1]);
		
		name = argv[1];

		err = 0;
/////////////////////////////////////////////////////////
	}
	else
	{
		cout<<"Errore di chiamata di page !!!"<<'\n';
		err = 1;
	}

	if (err == 0)
	{
/////////////////////////////////////////////////////////
		name_file_IN = name;
		name_file_OUT = name;
		name_file_LOG = name;

		name_file_IN += ".cmi";
		name_file_OUT += ".tex";
		name_file_LOG += ".log";
/////////////////////////////////////////////////////////

		CoreMass cmass;

		Page p_buff;
		Page p_out;
	
		ifstream f(name_file_IN.c_str());

		Page p_input(f);
		
		cmass.Import(p_input);
		cmass.Control();
		cmass.Solve();
		ofstream file_log(name_file_LOG.c_str());
		ofstream file_out(name_file_OUT.c_str());

		cmass.Export(p_out);
	
		cmass.PPrn(p_buff);
		p_buff.Print(file_log);
		p_out.Print(file_out);
/////////////////////////////////////////////////////////
	}
	else
	{
		cout<<"CoreMass non processato !!!";
	}
	return 0;
}
